package work.mediway.common.domain.enums;

import cn.hutool.core.util.StrUtil;

/**
 * 数据库驱动类枚举
 *
 * @author lipengfei_ylrj <lipengfei_ylrj@mediway.cn><br/>
 * @date 2022/8/26
 */
public enum DriverEnum {
    DRIVER_CACHE("CACHE", "com.intersys.jdbc.CacheDriver"),

    DRIVER_IRIS("IRIS", "com.intersystems.jdbc.IRISDriver"),

    DRIVER_KUNDB("KUNDB", "com.mysql.cj.jdbc.Driver"),

    DRIVER_MYSQL("MYSQL", "com.mysql.cj.jdbc.Driver");
    /**
     * 数据库类型
     */
    private final String type;
    /**
     * 驱动类
     */
    private final String driver;

    DriverEnum(String type, String driver) {
        this.type = type;
        this.driver = driver;
    }

    public String getType() {
        return type;
    }


    public String getDriver() {
        return driver;
    }

    //根据传入的type动态获取name
    public static String getDriver(String type) {
        DriverEnum[] enums = values();

        for (DriverEnum driverEnum : enums) {
            if (StrUtil.equalsIgnoreCase(driverEnum.getType(), type)) {
                return driverEnum.getDriver();
            }
        }
        return null;
    }
}
